package com.corecloud.controller.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.corecloud.entity.SysDeptEntity;
import com.corecloud.service.OtherBaseService;
import com.corecloud.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 对外第三方数据接口
 *
 */
@Controller
@RequestMapping("/api")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")//解决跨域问题
public class OtherApiController {

	@Autowired
	private SysDeptService sysDeptService;
	@Autowired
	private OtherBaseService otherBaseService;


	/**
	 * 获取机构相关数据
	 * @return
	 */
	@RequestMapping("/getDeptData")
	@ResponseBody
	public List<SysDeptEntity> getDeptData(String deptName,String areaCode,String deptType,Integer deptId){
		QueryWrapper qw = new QueryWrapper<SysDeptEntity>();
		if(!StringUtils.isEmpty(deptName)){
			qw.like("dept_name",deptName);
		}
		if(!StringUtils.isEmpty(areaCode)){
			qw.like("area_id",areaCode);
		}
		if(!StringUtils.isEmpty(deptType)){
			qw.like("dept_type",deptType);
		}
		if(!StringUtils.isEmpty(deptId)){
			qw.like("id",deptId);
		}
		return sysDeptService.selectList(qw);
	}



	/**
	 * 获取统计数据(机构，用户，第三方平台)
	 * @return
	 */
	@RequestMapping("/getStatisticsData")
	@ResponseBody
	public Map<String,Object> getStatisticsData(){
		return otherBaseService.getWelcomePageData();
	}

}
